package tags;

import javax.faces.component.UIComponent;
import javax.faces.webapp.UIComponentELTag;
import javax.servlet.jsp.JspException;


public class SliderTag extends UIComponentELTag
{
    private String value;
    private String minimumValue;
    private String maximumValue;
    private TrackTag trackTag;
    private HandleTag handleTag;

    public String getComponentType()
    {
        return "uicomponents.UISlider";
    }

    public String getRendererType()
    {
        return null;
    }

    @Override
    protected void setProperties(UIComponent component)
    {
        super.setProperties(component);

        if (value != null)
            component.getAttributes().put("value", value);
        if (minimumValue != null)
            component.getAttributes().put("minimumValue", minimumValue);
        if (maximumValue != null)
            component.getAttributes().put("maximumValue", maximumValue);
    }

    @Override
    public void release()
    {
        super.release();
        value = null;
        minimumValue = null;
        maximumValue = null;
        trackTag = null;
        handleTag = null;
    }

    public void setValue(String value)
    {
        this.value = value;
    }

    public void setMinimumValue(String minimumValue)
    {
        this.minimumValue = minimumValue;
    }

    public void setMaximumValue(String maximumValue)
    {
        this.maximumValue = maximumValue;
    }

    public void setTrackTag(TrackTag trackTag) throws JspException {
        if (this.trackTag != null)
            throw new JspException("There cannot be more than one TrackTag in SliderTag.");
        this.trackTag = trackTag;
        if (trackTag != null)
        {
            if (trackTag.getWidth() != null)
                this.getComponentInstance().getAttributes().put("trackWidth", trackTag.getWidth());
            if (trackTag.getHeight() != null)
                this.getComponentInstance().getAttributes().put("trackHeight", trackTag.getHeight());
            if (trackTag.getColor() != null)
                this.getComponentInstance().getAttributes().put("trackColor", trackTag.getColor());
        }
    }

    public void setHandleTag(HandleTag handleTag) throws JspException {
        if (this.handleTag != null)
            throw new JspException("There cannot be more than one HandleTag in SliderTag.");
        this.handleTag = handleTag;
        if (handleTag != null)
        {
            if (handleTag.getWidth() != null)
                this.getComponentInstance().getAttributes().put("handleWidth", handleTag.getWidth());
            if (handleTag.getHeight() != null)
                this.getComponentInstance().getAttributes().put("handleHeight", handleTag.getHeight());
            if (handleTag.getColor() != null)
                this.getComponentInstance().getAttributes().put("handleColor", handleTag.getColor());
        }
    }
}
